/*
 * @lc app=leetcode.cn id=234 lang=javascript
 *
 * [234] 回文链表
 */

// @lc code=start
/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
/**
 * @param {ListNode} head
 * @return {boolean}
 */
var isPalindrome = function(head) {
    if (!head) {
        return true
    }
    let arr = [head.val]
    let flag = true
    const palindrome = function(head) {
        if (head.next) {
            arr.push(head.next.val)
            palindrome(head.next)
        }
    }
    palindrome(head)
    while(arr.length !== 0 && arr.length !== 1) {
        if (arr.pop() !== arr.shift()) {
            flag = false
            break
        }
    }
    return flag
};
// @lc code=end

